<?php 

class Filter

{
	public function __Construct()
	{
		include_once 'dataBaseConnectivityFile.php';
	}

public function CountUsedCars()
{
	
			$getUsedCars=mysql_query("SELECT * from stock where `CONDITION` ='Used'");
			$countUsedCar=mysql_num_rows($getUsedCars);
			return $countUsedCar;	
		
		
}

public function CountNewCars()
{
		   $getNewCars=mysql_query("SELECT * from  stock where `CONDITION` ='New'");
			$countNewCar=mysql_num_rows($getNewCars);
			return $countNewCar;	
}
public function CountOther($Field,$Value)
{
	$GValue=$Value+5;
	if($Field=="MILEAGE")
	{
		
		 $getCars=mysql_query("SELECT * from  stock where MILEAGE < $Value AND MILEAGE != 0");
			$countCar=mysql_num_rows($getCars);
		
			return $countCar;
	}
	elseif($Field=="CITY_MILES_PER_GALLON")
	{
	
		   $getCars=mysql_query("SELECT * from  stock where CITY_MILES_PER_GALLON BETWEEN $Value and $GValue");
		   
			$countCar=mysql_num_rows($getCars);
			return $countCar;
	}
	else if($Field=="HIGHWAY_MILES_PER_GALLON")
	{
		
		$getCars=mysql_query("SELECT * from  stock where HIGHWAY_MILES_PER_GALLON BETWEEN $Value and $GValue");
			$countCar=mysql_num_rows($getCars);
			return $countCar;
	}
	else
	{
	
	       $getCars=mysql_query("SELECT * from  stock where `$Field` ='$Value'");
			$countCar=mysql_num_rows($getCars);
			return $countCar;	
	}
}


public function getCars()
{
    	$UsedCars=array();
		$getUsedCars=mysql_query("SELECT * from stock where `CONDITION`is not NULL");
			while($UsedCarRow=mysql_fetch_array($getUsedCars))
			{
				$UsedCars[]=array($UsedCarRow['STOCK_ID'],$UsedCarRow['TITLE'],$UsedCarRow['MAKE'],$UsedCarRow['BODY_STYLE'],
				$UsedCarRow['START_YEAR'],$UsedCarRow['END_YEAR'],$UsedCarRow['MILEAGE'],$UsedCarRow['TRANSMISSION'],$UsedCarRow['DRIVE_TRAIN'],
				$UsedCarRow['EXTERIOR_COLOR'],$UsedCarRow['INTERIOR_COLOR'],$UsedCarRow['FUEL_TYPE'],$UsedCarRow['CITY_MILES_PER_GALLON'],
				$UsedCarRow['HIGHWAY_MILES_PER_GALLON'],$UsedCarRow['STATUS'],$UsedCarRow['PRICE'],$UsedCarRow['CONTACT_NO'],$UsedCarRow[
				'IMAGE_PATH'],$UsedCarRow['CREATE_DATE'],$UsedCarRow['MODIFIED_DATE'],$UsedCarRow['ENGINE'],$UsedCarRow['CONDITION'],$UsedCarRow['MODEL_NUMBER']);
			}
			return $UsedCars;			
}
public function getFilteredCars($Criteria,$Value)
{
	
    	$UsedCars=array();
		$getUsedCars=mysql_query("SELECT * from stock ");
			while($UsedCarRow=mysql_fetch_array($getUsedCars))
			{
				if($Criteria=="START_YEAR")
				{
					if($UsedCarRow[$Criteria]>=$Value)
					{
						$UsedCars[]=array($UsedCarRow['STOCK_ID'],$UsedCarRow['TITLE'],$UsedCarRow['MAKE'],$UsedCarRow['BODY_STYLE'],
				$UsedCarRow['START_YEAR'],$UsedCarRow['END_YEAR'],$UsedCarRow['MILEAGE'],$UsedCarRow['TRANSMISSION'],$UsedCarRow['DRIVE_TRAIN'],
				$UsedCarRow['EXTERIOR_COLOR'],$UsedCarRow['INTERIOR_COLOR'],$UsedCarRow['FUEL_TYPE'],$UsedCarRow['CITY_MILES_PER_GALLON'],
				$UsedCarRow['HIGHWAY_MILES_PER_GALLON'],$UsedCarRow['STATUS'],$UsedCarRow['PRICE'],$UsedCarRow['CONTACT_NO'],$UsedCarRow[
				'IMAGE_PATH'],$UsedCarRow['CREATE_DATE'],$UsedCarRow['MODIFIED_DATE'],$UsedCarRow['ENGINE'],$UsedCarRow['CONDITION'],$UsedCarRow['MODEL_NUMBER']);
					}
				}
				else if($Criteria=="HIGHWAY_MILES_PER_GALLON" || $Criteria=="CITY_MILES_PER_GALLON")
				{
					if($UsedCarRow[$Criteria]>=$Value && $UsedCarRow[$Criteria]<=$Value+5)
					{
						$UsedCars[]=array($UsedCarRow['STOCK_ID'],$UsedCarRow['TITLE'],$UsedCarRow['MAKE'],$UsedCarRow['BODY_STYLE'],
				$UsedCarRow['START_YEAR'],$UsedCarRow['END_YEAR'],$UsedCarRow['MILEAGE'],$UsedCarRow['TRANSMISSION'],$UsedCarRow['DRIVE_TRAIN'],
				$UsedCarRow['EXTERIOR_COLOR'],$UsedCarRow['INTERIOR_COLOR'],$UsedCarRow['FUEL_TYPE'],$UsedCarRow['CITY_MILES_PER_GALLON'],
				$UsedCarRow['HIGHWAY_MILES_PER_GALLON'],$UsedCarRow['STATUS'],$UsedCarRow['PRICE'],$UsedCarRow['CONTACT_NO'],$UsedCarRow[
				'IMAGE_PATH'],$UsedCarRow['CREATE_DATE'],$UsedCarRow['MODIFIED_DATE'],$UsedCarRow['ENGINE'],$UsedCarRow['CONDITION'],$UsedCarRow['MODEL_NUMBER']);
					
					}
				}
				else if($Criteria=="MILEAGE")
				{
					
					
					if($UsedCarRow[$Criteria]<$Value && $UsedCarRow[$Criteria]>0)
					{
						
						$UsedCars[]=array($UsedCarRow['STOCK_ID'],$UsedCarRow['TITLE'],$UsedCarRow['MAKE'],$UsedCarRow['BODY_STYLE'],
				$UsedCarRow['START_YEAR'],$UsedCarRow['END_YEAR'],$UsedCarRow['MILEAGE'],$UsedCarRow['TRANSMISSION'],$UsedCarRow['DRIVE_TRAIN'],
				$UsedCarRow['EXTERIOR_COLOR'],$UsedCarRow['INTERIOR_COLOR'],$UsedCarRow['FUEL_TYPE'],$UsedCarRow['CITY_MILES_PER_GALLON'],
				$UsedCarRow['HIGHWAY_MILES_PER_GALLON'],$UsedCarRow['STATUS'],$UsedCarRow['PRICE'],$UsedCarRow['CONTACT_NO'],$UsedCarRow[
				'IMAGE_PATH'],$UsedCarRow['CREATE_DATE'],$UsedCarRow['MODIFIED_DATE'],$UsedCarRow['ENGINE'],$UsedCarRow['CONDITION'],$UsedCarRow['MODEL_NUMBER']);
					
					}
				}
				else
				{
				if(!strstr($UsedCarRow[$Criteria],$Value)===FALSE){
					
				$UsedCars[]=array($UsedCarRow['STOCK_ID'],$UsedCarRow['TITLE'],$UsedCarRow['MAKE'],$UsedCarRow['BODY_STYLE'],
				$UsedCarRow['START_YEAR'],$UsedCarRow['END_YEAR'],$UsedCarRow['MILEAGE'],$UsedCarRow['TRANSMISSION'],$UsedCarRow['DRIVE_TRAIN'],
				$UsedCarRow['EXTERIOR_COLOR'],$UsedCarRow['INTERIOR_COLOR'],$UsedCarRow['FUEL_TYPE'],$UsedCarRow['CITY_MILES_PER_GALLON'],
				$UsedCarRow['HIGHWAY_MILES_PER_GALLON'],$UsedCarRow['STATUS'],$UsedCarRow['PRICE'],$UsedCarRow['CONTACT_NO'],$UsedCarRow[
				'IMAGE_PATH'],$UsedCarRow['CREATE_DATE'],$UsedCarRow['MODIFIED_DATE'],$UsedCarRow['ENGINE'],$UsedCarRow['CONDITION'],$UsedCarRow['MODEL_NUMBER']);
			}
				}
			}
			return $UsedCars;			
}

public function FilterCares($test=array(),$Criteria,$Value)
{
	//var_dump($test);
	$filterd=array();
	foreach($test as $key => $Car)
	{
		if($Criteria=="MILEAGE")
		{
        if($Car[6]<$Value)
			{
				$filterd[]=$test[$key];
			}
				
		}
		else if($Criteria=="CITY_MILES_PER_GALLON")
		{
			if($Car[12]>=$Value && $Car[12]<=$Value+5)
			{
				$filterd[]=$test[$key];
			}
		}
		else if($Criteria=="HIGHWAY_MILES_PER_GALLON")
		{
			$V=$Value+5;
		
			if($Car[13]>=$Value && $Car[13]<=$V)
			{
				
				$filterd[]=$test[$key];
			}
		}
		else if($Criteria=="START_YEAR")
		{
		
		
			
			if($Car[4]>=$Value)
			{
				$filterd[]=$test[$key];
			}
		}
		
		else if($Criteria=="END_YEAR")
		{
			
			if($Car[5]<=$Value)
			{
				$filterd[]=$test[$key];
			}
		}
		
		
		else{
		for($i=0;$i<sizeof($Car);$i++)
		{
			
			
			if($Car[$i]==$Value)
			{
				$filterd[]=$test[$key];
			}
		}
		}
	}
	return $filterd;
}
public function getCarCompany()
{
	$MakeCar=array();
	$getMakeCars=mysql_query("SELECT * FROM stock GROUP BY MAKE");
	
     while($MakeCarsRow=mysql_fetch_array($getMakeCars)){
			
			$MakeCar[]=array($MakeCarsRow['STOCK_ID'],$MakeCarsRow['MAKE']);			
}
return $MakeCar;
}

public function getBodyStyle()
{
	$BodyStyle=array();
	$getBodyStyle=mysql_query("SELECT * FROM stock GROUP BY BODY_STYLE");
	
     while($BodyStyleRow=mysql_fetch_array($getBodyStyle)){
			
			$BodyStyle[]=array($BodyStyleRow['STOCK_ID'],$BodyStyleRow['BODY_STYLE']);			
}
return $BodyStyle;
}
public function getTransmission()
{
	$Trans=array();
	$getTrans=mysql_query("SELECT * FROM stock GROUP BY TRANSMISSION");
	
     while($TransRow=mysql_fetch_array($getTrans)){
			
			$Trans[]=array($TransRow['STOCK_ID'],$TransRow['TRANSMISSION']);			
}
return $Trans;
}
public function getDriverTrain()
{
	$CarProperty=array();
	$getCarPro=mysql_query("SELECT * FROM stock GROUP BY DRIVE_TRAIN");
	
     while($PropertyRow=mysql_fetch_array($getCarPro)){
			
			$CarProperty[]=array($PropertyRow['STOCK_ID'],$PropertyRow['DRIVE_TRAIN']);			
}
return $CarProperty;
}
public function getExteriorColor()
{
	$CarProperty=array();
	$getCarPro=mysql_query("SELECT * FROM stock GROUP BY EXTERIOR_COLOR");
	
     while($PropertyRow=mysql_fetch_array($getCarPro)){
			
			$CarProperty[]=array($PropertyRow['STOCK_ID'],$PropertyRow['EXTERIOR_COLOR']);			
}
return $CarProperty;
}
public function getInteriorColor()
{
	$CarProperty=array();
	$getCarPro=mysql_query("SELECT * FROM stock GROUP BY INTERIOR_COLOR");
	
     while($PropertyRow=mysql_fetch_array($getCarPro)){
			
			$CarProperty[]=array($PropertyRow['STOCK_ID'],$PropertyRow['INTERIOR_COLOR']);			
}
return $CarProperty;
}
public function getFuelType()
{
	$CarProperty=array();
	$getCarPro=mysql_query("SELECT * FROM stock GROUP BY FUEL_TYPE");
	
     while($PropertyRow=mysql_fetch_array($getCarPro)){
			
			$CarProperty[]=array($PropertyRow['STOCK_ID'],$PropertyRow['FUEL_TYPE']);			
}
return $CarProperty;
}
public function getCityMiles()
{
	$CarProperty=array();
	$getCarPro=mysql_query("SELECT * FROM stock GROUP BY CITY_MILES_PER_GALLON");
	
     while($PropertyRow=mysql_fetch_array($getCarPro)){
			
			$CarProperty[]=array($PropertyRow['STOCK_ID'],$PropertyRow['CITY_MILES_PER_GALLON']);			
}
return $CarProperty;
}
public function getHighWayMiles()
{
	$CarProperty=array();
	$getCarPro=mysql_query("SELECT * FROM stock GROUP BY HIGHWAY_MILES_PER_GALLON");
	
     while($PropertyRow=mysql_fetch_array($getCarPro)){
			
			$CarProperty[]=array($PropertyRow['STOCK_ID'],$PropertyRow['HIGHWAY_MILES_PER_GALLON']);			
}
return $CarProperty;
}
public function getPhotos($stockID)
{
	$getCarPro=mysql_query("SELECT * FROM vehicle_image WHERE STOCK_ID='$stockID'");
	$rows=mysql_num_rows($getCarPro);
	return $rows;	
}
}


?>